Crate unsize[−][src]
This module encapsulates correct coercers and coercible pointers.
The act of Coercion, a special kind of somewhat trivial pointer conversion, is not exposed as a safe trait. There are two unsafe traits: The first captures which structs unsized to which dynamically sized types; which the second is applied to (wrappers around) pointers that can be coerced implicitly.
We do not have the luxury of compiler builtin checks to enforce that a particular pointer conversion is sound, nor can we generate the tag of target fat pointer from thin air. Instead, we use a trick. Note that both of these safety issues occur in the context of the pointer conversion. Now, we can require the user to unsafely provide a function that implements the conversion correctly. The using this function is safe and enables any particular user-defined pointer wrapper to safely transform itself. Note that for a limited selection of standard traits we can even go so far as offer pre-built converters that are safe to use in general.
Macros
Coercion | Non- |
Structs
Coercion | Enables the unsizing of a sized pointer. |
Traits
CoerceUnsize | An extension trait using |
CoerciblePtr | Add unsizing methods to pointer-like types. |